package com.yoda.mall.admin.service;

import com.yoda.mall.api.*;
import com.yoda.mall.model.dto.HomeBrandDto;
import com.yoda.mall.model.entity.sms.HomeBrand;

import com.yoda.mall.model.entity.sms.HomeNewProduct;
import com.yoda.mall.model.entity.sms.HomeRecommendProduct;
import com.yoda.mall.model.entity.sms.HomeRecommendSubject;
import com.yoda.mall.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author shawn
 * @date 2022年 12月 16日 15:06
 */
@Service
public class HomeService {

    @DubboReference
    private BrandApi brandApi;

    @DubboReference
    private ProductApi productApi;

    @DubboReference
    private HomeBrandApi homeBrandApi;

    @DubboReference
    private HomeNewProductApi homeNewProductApi;

    @DubboReference
    private HomeRecommendProductApi homeRecommendProductApi;

    @DubboReference
    private HomeRecommendSubjectApi homeRecommendSubjectApi;






    /**
     * 得到推荐品牌
     *
     * @param page            页面
     * @param pageSize        页面大小
     * @param brandName       品牌名称
     * @param recommendStatus 推荐状态
     * @return {@link PageResult}<{@link HomeBrand}>
     */
    public PageResult<HomeBrand> getRecommendBrands(Integer page, Integer pageSize, String brandName, Integer recommendStatus) {

        return homeBrandApi.selectByPage(page,pageSize,brandName,recommendStatus);
    }

    public Integer createRecommendBrand( List<HomeBrandDto> homeBrandList) {
        if (homeBrandList.size()==0){
            return 0;
        }
        List<HomeBrand> homeBrands = homeBrandList.stream().map(HomeBrandDto::init).collect(Collectors.toList());
        return homeBrandApi.createRecommendBrand(homeBrands);
    }

    public void updateHomeBrandById(List<Long> ids ,Integer recommendStatus) {
        homeBrandApi.updateHomeBrandById(ids,recommendStatus);
    }

    public void changeBrandSort(Long id, Integer sort) {
        homeBrandApi.changeBrandSort(id,sort);
    }

    public void deleteByIds(List<Long> ids) {
        homeBrandApi.deleteByIds(ids);
    }

    public PageResult<HomeNewProduct> getNewProductPage(Integer page, Integer pageSize, String productName, Integer recommendStatus) {
        return homeNewProductApi.selectNewProductByPage(page,pageSize,productName,recommendStatus);
    }

    public void changeNewProductSort(Long id, Integer sort) {
        homeNewProductApi.changeNewProductSort(id,sort);
    }

    public void updateNewProductStatus(List<Long> ids, Integer recommendStatus) {
        homeNewProductApi.updateNewProductStatus(ids,recommendStatus);
    }

    public void deleteNewProductByIds(List<Long> ids) {
        homeNewProductApi.deleteByIds(ids);
    }

    public PageResult<HomeRecommendProduct> getHomeRecommendProductPage(Integer page, Integer pageSize, String productName, Integer recommendStatus) {
        return homeRecommendProductApi.getHomeRecommendProductPage(page,pageSize,productName,recommendStatus);
    }

    public void changeRecommendProductSort(Long id, Integer sort) {
        homeRecommendProductApi.changeRecommendProductSort(id,sort);
    }

    public void updateRecommendProductStatus(List<Long> ids, Integer recommendStatus) {
        homeRecommendProductApi.updateRecommendProductStatus(ids,recommendStatus);
    }

    public void deleteRecommendProductByIds(List<Long> ids) {
        homeRecommendProductApi.deleteRecommendProductByIds(ids);
    }

    public void deleteRecommendSubjectByIds(List<Long> ids) {
        homeRecommendSubjectApi.deleteRecommendSubjectByIds(ids);
    }

    public void updateRecommendSubjectStatus(List<Long> ids, Integer recommendStatus) {
        homeRecommendSubjectApi.updateRecommendSubjectStatus(ids,recommendStatus);
    }

    public void changeRecommendSubjectSort(Long id, Integer sort) {
        homeRecommendSubjectApi.changeRecommendSubjectSort(id,sort);
    }

    public PageResult<HomeRecommendSubject> getRecommendSubjectPage(Integer page, Integer pageSize, String subjectName, Integer recommendStatus) {
        return homeRecommendSubjectApi.getRecommendSubjectPage(page,pageSize,subjectName,recommendStatus);
    }
}
